/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import Control.Point;
import Model.SimplePaintCanvas3;
import Model.Curve;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author PhucAnh
 */
public class Star extends Shape{
    Point pointStart;
    Point pointFinish;
    
    int xa,ya,xb,yb,xc,yc,xd,yd,xe,ye,xtemp,ytemp,xtemp1,ytemp1,xtemp2,ytemp2;
   
    int listX[] = new int[6];
    int listY[] = new int[6];
    
    public Star() {

    }

    public Star(Point pointStart, Point pointFinish, Color color, int basicStrok) {
        super(color, basicStrok);
        this.pointStart = pointStart;
        this.pointFinish = pointFinish;
        
        xa = (pointStart.getX() + pointFinish.getX())/2;
        ya = pointStart.getY();
        
        xb = pointFinish.getX();
        yb = (int) (pointStart.getY() + (pointFinish.getY() - pointStart.getY())/3);
        
        xtemp = xa;
        ytemp = pointFinish.getY();
        
        xtemp1 = xtemp + (pointFinish.getX() - xtemp)/3;
        ytemp1 = ytemp;
        
        xtemp2 = xtemp - (xtemp - pointStart.getX())/3;
        ytemp2 = ytemp;
        
        xc = (pointFinish.getX() + xtemp1)/2;
        yc = ytemp;
        
        xd = (pointStart.getX() + xtemp2)/2;
        yd = ytemp;
        
        xe = pointStart.getX();
        ye = yb;
        
        listX[0]=xd;
        listX[1]=xa;
        listX[2]=xc;
        listX[3]=xe;
        listX[4]=xb;
        listX[5]=xd;
        
        listY[0]=yd;
        listY[1]=ya;
        listY[2]=yc;
        listY[3]=ye;
        listY[4]=yb;
        listY[5]=yd;
    }
    
        public void setPoint2(Point pointFinish){
            this.pointFinish = pointFinish;
        
        xa = (pointStart.getX() + pointFinish.getX())/2;
        ya = pointStart.getY();
        
        xb = pointFinish.getX();
        yb = (int) (pointStart.getY() + (pointFinish.getY() - pointStart.getY())/3);
        
        xtemp = xa;
        ytemp = pointFinish.getY();
        
        xtemp1 = xtemp + (pointFinish.getX() - xtemp)/3;
        ytemp1 = ytemp;
        
        xtemp2 = xtemp - (xtemp - pointStart.getX())/3;
        ytemp2 = ytemp;
        
        xc = (pointFinish.getX() + xtemp1)/2;
        yc = ytemp;
        
        xd = (pointStart.getX() + xtemp2)/2;
        yd = ytemp;
        
        xe = pointStart.getX();
        ye = yb;
        
        listX[0]=xd;
        listX[1]=xa;
        listX[2]=xc;
        listX[3]=xe;
        listX[4]=xb;
        listX[5]=xd;
        
        listY[0]=yd;
        listY[1]=ya;
        listY[2]=yc;
        listY[3]=ye;
        listY[4]=yb;
        listY[5]=yd;
        }
    
    @Override
    public void drawShape(Graphics g2,BufferedImage img)
    {
        Point pointA = new Point(xa, ya);
        Point pointB = new Point(xb, yb);
        Point pointC = new Point(xc, yc);
        Point pointD = new Point(xd, yd);
        Point pointE = new Point(xe, ye);
        
        Graphics2D g= (Graphics2D)g2;
        g.setStroke(new BasicStroke(this.getBasicStroke()));
        g.setColor(this.getColor());
        g.drawPolygon(listX, listY, 6);
    }
    @Override
    public void toMove(int m,int n)
    {
        for(int i=0;i<6;i++){
            listX[i]+=m;
            listY[i]+=n;
        }
    }
    
    @Override
    public boolean isContain(Point p){
        if(pointFinish.getX()>=pointStart.getX() && pointFinish.getY()>=pointStart.getY()){
            if(p.getX()>= pointStart.getX() && p.getX()<= pointFinish.getX() 
            && p.getY()>= pointStart.getY() && p.getY()<= pointFinish.getY()){
                return true;
            } else {
                return false;
            }
        } else if (pointFinish.getX()<pointStart.getX() && pointFinish.getY()<pointStart.getY()){
            if(p.getX()>= pointFinish.getX() && p.getX()<= pointStart.getX() 
            && p.getY()>= pointFinish.getY() && p.getY()<= pointStart.getY()){
                return true;
            } else {
                return false;
            }
        } else if (pointFinish.getX()>=pointStart.getX() && pointFinish.getY()<=pointStart.getY()){
            if(p.getX()>= pointStart.getX() && p.getX()<= pointFinish.getX() 
            && p.getY()>= pointFinish.getY() && p.getY()<= pointStart.getY()){
                return true;
            } else {
                return false;
            }
        } else {
            if(p.getX()>= pointFinish.getX() && p.getX()<= pointStart.getX() 
            && p.getY()>= pointStart.getY() && p.getY()<= pointFinish.getY()){
                return true;
            } else {
                return false;
            }
        }
    }
    

    public void drawShape1(Graphics g,int time,Image a,SimplePaintCanvas3 a2){
        int x=pointFinish.getX()- pointStart.getX();
        int y=pointFinish.getY()- pointStart.getY();
        Graphics2D g2D = (Graphics2D)g;
        g2D.setStroke(new BasicStroke(this.getBasicStroke()));
        g.setColor(this.getColor());
        Image img = a;
        Point tmp=new Point();
        for(int i=0;i<=time;i++){
          g.drawImage(img,0, 0, a2);
            tmp.setX(x*i/time+pointStart.getX());
            tmp.setY(y*i/time+pointStart.getY());
            setPoint2(tmp);
//            g.drawOval(this.x, this.y, width, height);
        g.drawPolygon(listX, listY, 6);
                        try {
                                Thread.sleep(time);
                            } catch (InterruptedException ex) {
                                Logger.getLogger(Curve.class.getName()).log(Level.SEVERE, null, ex);
                            }
        }
    }
}
